package com.qianxx.base;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.annotation.VisibleForTesting;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.qianxx.utils.ToastUtil;

/**
 * Created on 16/5/19 下午5:30.
 *
 * @author binwin20
 */
public class LibBaseFragment extends Fragment {
    protected View mView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return mView;
    }

    @VisibleForTesting
    public View getView() {
        return mView;
    }


    public void showLoadingView(boolean fullScreen) {
        if (!isAdded()) return;
        if (getActivity() instanceof LibBaseActivity) {
            ((LibBaseActivity) getActivity()).showLoadingView(fullScreen);
        }
    }

    public void hideLoadingView() {
        if (getActivity() instanceof LibBaseActivity) {
            ((LibBaseActivity) getActivity()).hideLoadingView();
        }
    }

    public void toast(String msg) {
        ToastUtil.getInstance().toast(msg);
    }


    public void toast(@StringRes int msgId) {
        ToastUtil.getInstance().toast(msgId);
    }

    public void visible(View... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setVisibility(View.VISIBLE);
        }
    }

    public void invisible(View... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setVisibility(View.INVISIBLE);
        }
    }
    
    public void gone(View... views) {
        for (int i = 0; i < views.length; i++) {
            views[i].setVisibility(View.GONE);
        }
    }

}
